package com.meng.learn.swagger.controller;

import com.alibaba.fastjson.JSON;
import com.meng.learn.swagger.vo.UserVO;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/swagger")
@Api(tags="用户模块")
public class SwaggerDemoController {

    private static Logger logger = LoggerFactory.getLogger(SwaggerDemoController.class);

    @RequestMapping("/test1")
    @ApiOperation(value="用户测试",notes="测试swagger")
    @ApiImplicitParams({
            @ApiImplicitParam(name="mobile",value="手机号",required=true,paramType="form"),
            @ApiImplicitParam(name="password",value="密码",required=true,paramType="form"),
            @ApiImplicitParam(name="age",value="年龄",required=true,paramType="form",dataType="Integer")
    })
    @ApiResponses({
            @ApiResponse(code = 400, message = "请求参数没填好"),
            @ApiResponse(code = 404, message = "请求路径没有或页面跳转路径不对")
    })
    public String test1(UserVO user, @RequestParam String extraInfo) {

        return "test1" + JSON.toJSONString(user)  + extraInfo;
    }


    @RequestMapping("/test2")
    @ApiOperation(value="用户测试",notes="测试swagger")
    @ApiImplicitParams({
            @ApiImplicitParam(name="user", dataType = "UserVO", value="用户信息", paramType="body", required=true),
            @ApiImplicitParam(name="extraInfo", dataType="String", value="年龄", paramType="form")
    })
    @ApiResponses({
            @ApiResponse(code = 400, message = "请求参数没填好"),
            @ApiResponse(code = 404, message = "请求路径没有或页面跳转路径不对")
    })
    public String test2(@RequestBody UserVO user, @RequestParam String extraInfo) {

        return "test2" + JSON.toJSONString(user)  + extraInfo;
    }

    @RequestMapping("/test3")
    @ApiOperation(value="用户测试",notes="测试swagger")
    @ApiImplicitParams({
            @ApiImplicitParam(name="user", dataType = "UserVO", value="用户信息", paramType="body", required=true),
    })
    @ApiResponses({
            @ApiResponse(code = 400, message = "请求参数没填好"),
            @ApiResponse(code = 404, message = "请求路径没有或页面跳转路径不对")
    })
    public String test3(@RequestBody UserVO user) {

        return "test3" + JSON.toJSONString(user);
    }

    // 比较日期大小
}
